home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
lib
/
c
/
stdio
/
RCS
/
fwrite.c,v
< prev
next >
Wrap
Text File
|
1991-12-02
|
3KB
|
143 lines
head 1.2;
branch ;
access ;
symbols sprited:1.2.1;
locks ; strict;
comment @ * @;
1.2
date 91.05.29.16.49.45; author shirriff; state Exp;
branches 1.2.1.1;
next 1.1;
1.1
date 88.06.10.16.23.53; author ouster; state Exp;
branches ;
next ;
1.2.1.1
date 91.12.02.19.58.30; author kupfer; state Exp;
branches ;
next ;
desc
@@
1.2
log
@Changed fread, fwrite to work a chunk at a time instead of a character
at a time.
@
text
@/*
* fwrite.c --
*
* Source code for the "fwrite" library procedure.
*
* Copyright 1988 Regents of the University of California
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#ifndef lint
static char rcsid[] = "$Header: /sprite/src/lib/c/stdio/RCS/fwrite.c,v 1.1 88/06/10 16:23:53 ouster Exp Locker: shirriff $ SPRITE (Berkeley)";
#endif not lint
#include "stdio.h"
/*
*----------------------------------------------------------------------
*
* fwrite --
*
* This procedure outputs binary data to a buffered stream.
*
* Results:
* The return value is the number of complete items actually written.
* It may be less than numItems if an error condition was encountered;
* in this case, there may be an additional partial item output after
* the complete items.
*
* Side effects:
* Up to numItems*size bytes are written into the stream from memory at
* buf.
*
*----------------------------------------------------------------------
*/
int
fwrite(bufferPtr, size, numItems, stream)
register char *bufferPtr; /* Origin of items to be written on stream.
* Must contain numItems*size bytes. */
int size; /* Size of each item to be written. */
int numItems; /* Number of items to be written. */
register FILE *stream; /* Stream where bytes are to be written. */
{
register int num, byteCount, itemCount;
for (itemCount = 0; itemCount < numItems; itemCount++) {
for (byteCount = size; byteCount > 0;) {
if (stream->writeCount <=1 || stream->flags & STDIO_LINEBUF) {
if (fputc(*bufferPtr, stream) == EOF) {
return(itemCount);
}
bufferPtr++;
byteCount--;
} else {
num = stream->writeCount-1 < byteCount ? stream->writeCount-1
: byteCount;
bcopy(bufferPtr, stream->lastAccess+1, num);
stream->writeCount -= num;
stream->lastAccess += num;
bufferPtr += num;
byteCount -= num;
}
}
}
return(numItems);
}
@
1.2.1.1
log
@Initial branch for Sprite server.
@
text
@d17 1
a17 1
static char rcsid[] = "$Header: /sprite/src/lib/c/stdio/RCS/fwrite.c,v 1.2 91/05/29 16:49:45 shirriff Exp $ SPRITE (Berkeley)";
@
1.1
log
@Initial revision
@
text
@d17 1
a17 1
static char rcsid[] = "$Header: atoi.c,v 1.1 88/04/28 17:20:23 ouster Exp $ SPRITE (Berkeley)";
a49 1
register int itemCount, byteCount;
d51 2
d54 17
a70 6
for (byteCount = 0; byteCount < size; byteCount++) {
if (putc(*bufferPtr, stream) == EOF) {
return(itemCount);
}
bufferPtr++;
}
@